<template>
  <div>
    <uploadExcel :on-success="onSuccess" />
  </div>
</template>

<script>
import { sysUserBatch } from '@/api/employees'
export default {
  methods: {
    async onSuccess(res) {
      const newArr = res.results.map((item) => {
        return {
          timeOfEntry: this.excelTimeToJsTime(item['入职日期']),
          username: item['姓名'],
          workNumber: item['工号'],
          mobile: item['手机号'],
          correctionTime: this.excelTimeToJsTime(item['转正日期'])
        }
      })
      await sysUserBatch(newArr)
      this.$message.success('导入成功')
      this.$router.push('/employees')
      console.log(res.results, newArr)
    },
    excelTimeToJsTime(excelTime) {
      const num = (excelTime - 1) * 24 * 60 * 60 * 1000 - 8 * 60 * 60 * 1000
      const time = new Date(num) // 1970年算的
      time.setYear(time.getFullYear() - 70)
      return time
    }
  }
}
</script>

<style></style>
